<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

if(get('cron')==''){
    JFX::addError($this->lang('invalid_id'));
    JFX::redirect($this->adminUrl);
}

$cronid = (int) get('cron');

if($DB->countRows($CONFIG->dbprefix.'croncontrol_crons', "id = '{$cronid}'")==0){
    JFX::addError($this->lang('invalid_id'));
    JFX::redirect($this->adminUrl);
}













if(Antz_IntelliForm::submitted('edit-cron')){
    // check and process
    $error = false;
    $schedule = post('schedule');
    $url = post('url');

    $nextRun = (int) $this->findNextRun($schedule);

    if($nextRun === 0){
        // error - invalid schedule
        $error = true;
        JFX::addError($this->lang('invalid_schedule'));
    }

    if(trim($url)==''){
        $error = true;
        JFX::addError($this->lang('invalid_url'));
    }

    if(!$error){
        // ok to process
        $dbParams = array(
            'schedule' => $schedule,
            'url' => $url,
            'next_run_tstamp' => $nextRun
        );
        $DB->update($CONFIG->dbprefix.'croncontrol_crons', $dbParams, "id = '{$cronid}'");
        JFX::addSuccess($this->lang('edit_success'));
        JFX::redirect($this->adminUrl);
    }

}













$cData = $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}croncontrol_crons WHERE id = '{$cronid}'");

// generate the form
$formFields = array(
    array(
        'type' => 'text',
        'name' => 'schedule',
        'label' => $this->lang('schedule'),
        'value' => post('schedule', $cData['schedule'])
    ),
    array(
        'type' => 'text',
        'name' => 'url',
        'label' => $this->lang('url'),
        'value' => post('url', $cData['url'])
    ),
    array(
        'type' => 'submit',
        'value' => $this->lang('submit'),
        'label' => '&nbsp;',
        'name' => 'submitBtn'
    )
);


echo JFX::makeRapidForm($formFields, $this->lang('edit_legend'), 'edit-cron');












